/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.pc.controller.ware;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.WareBrandPo;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.generic.connector.IWareBrandConnector;
import com.itttq.gshop.generic.controller.GenericController;

@RestController
@RequestMapping("ware/brand")
public class WareBrandController extends GenericController {
	private static final long serialVersionUID = 258159243851379819L;
	@Autowired
	private IWareBrandConnector wareBrandConnector;
	
	/**
	 * 根据条件查询WareBrandPo对象，并分页
	 * 
	 * @param wareBrand
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("brands.html")
	public ModelAndView getWareBrands(WareBrandPo wareBrand, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/ware/brands");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		wareBrand.setStart(ppt.getStart());
		wareBrand.setSize(ppt.getSize());
//		ResultPageTo<WareBrandPo> rpt = wareBrandConnector.getWareBrands(wareBrand);
		// this.getPageMv("brands", mv, rpt);
		mv.addObject("brand", wareBrand);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addWareBrand() {
		ModelAndView mv = new ModelAndView("/ware/brandAdd");
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewWareBrand(@PathVariable("id") Integer id) {
		ModelAndView mv = addWareBrand();
		if(id != null) {
			mv.addObject("brand", wareBrandConnector.getWareBrand(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editWareBrand(@PathVariable("id") Integer id) {
		ModelAndView mv = viewWareBrand(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存WareBrandPo对象，无ID则新增，有ID则更新
	 * 
	 * @param wareBrand
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ModelAndView saveWareBrand(WareBrandPo wareBrand) {
		wareBrandConnector.saveWareBrand(wareBrand);
		return getWareBrands(new WareBrandPo(), null);
	}

	/**
	 * 根据ID删除WareBrandPo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delWareBrand(@PathVariable("id") Integer id) {
		if(id != null) {
			wareBrandConnector.delWareBrand(id);
		}
		return getWareBrands(new WareBrandPo(), null);
	}
}